package com.gzbugu.polytechsasia.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gzbugu.polytechsasia.factory.DAOFactory;
import com.gzbugu.polytechsasia.vo.Article;

public class DataTrans extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		Article article = null;
		int id = Integer.parseInt(request.getParameter("id"));
		try {
			article = DAOFactory.getArticleDAO().findById(id);
		} catch (SQLException e) {
			response.sendRedirect("en/admin/manage.jsp");
		}
		request.setAttribute("article", article);
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("en/admin/modify.jsp");
		dispatcher.forward(request, response);
	}

}
